package com.assess.web.service.impl;

import com.assess.web.dao.AddressMapper;
import com.assess.web.model.Address;
import com.assess.web.model.AddressExample;
import com.assess.web.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public List<Address> listAddress(int companyId) {
        AddressExample example = new AddressExample();
        example.createCriteria().andCompanyIdEqualTo(companyId);
        return addressMapper.selectByExample(example);
    }

    @Override
    public Address getAddress(int addressId) {
        return addressMapper.selectByPrimaryKey(addressId);
    }

    @Override
    public int saveAddress(int companyId, String name) {
        Address address = new Address();
        address.setCompanyId(companyId);
        address.setName(name);
        return addressMapper.insertSelective(address);
    }
}
